// #define print(...)
using maxheap_t = multiset< int, greater<int> >;
class Solution {
public:
vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
    vector<vector<int>> skyLn; // 天际线
    // 建筑左右两侧竖线
    vector<pair<int,int>> vLn;
    vLn.reserve(buildings.size()*2);
    for(auto&b:buildings){
        vLn.push_back({b[0],-b[2]}); // 左侧竖线 x_left, -h
        vLn.push_back({b[1], b[2]}); // 右侧竖线 x_right, h
    }
    sort(vLn.begin(), vLn.end()); // 所有竖线沿 x 轴升序排列
    print("vLn=", vLn, "\n")
    // 用大顶堆存沿线经过的建筑高度
    maxheap_t heights({0});
    for(auto &[x,h] : vLn){
        if(h < 0) heights.insert(-h);        // 遇到左边，沿线进入建筑上空
        else heights.erase(heights.find(h)); // 遇到右边，沿线离开建筑上空
        if(skyLn.empty() || (*skyLn.rbegin())[1] != *heights.begin()){
            skyLn.push_back({x, *heights.begin()});
            print("(",x,",",*heights.begin(),") heights=", heights, "\n")
        }
    }
    return skyLn;
}
};
